<?php
/**
 * This file is part of PHPlaza (http://code.google.com/p/phplaza)
 * This file is licensed under the GNU Lesser General Public License
 *      http://www.gnu.org/licenses/lgpl.html
 *
 * No warranty is given, express or implied. Use at your own risk.
 */

namespace core::components;
abstract class ClickableComponent extends TextComponent implements IEventGenerator
{
	protected $onClick;
	
	public function __construct()
	{
		parent::__construct();
		$this->onClick = new core::collections::CList();
	}
	
	public function _getState(State $state)
	{
		parent::_getState($state);
		$state->__OnClick = $this->onClick;
	}
	
	public function _setState(State $state)
	{
		parent::_setState($state);
		$this->onClick = $state->__OnClick;
	}
	
	public function _handleRequest($data)
	{
		foreach($this->onClick as $handler)
		{
			call_user_func_array($handler, 
				array(
					'sender' => $this,
					null
				)
			);
		}
	}
	
	public function addOnClick(array $handler)
	{
		$this->onClick->add($handler);
	}
}